package cn.iocoder.yudao.module.system.service.portal;

import cn.iocoder.yudao.module.system.controller.admin.portal.vo.PortalDeptPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.portal.vo.PortalDeptRespVO;
import cn.iocoder.yudao.module.system.controller.admin.portal.vo.PortalDeptSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.portal.PortalDeptDO;

import cn.iocoder.yudao.module.system.dal.mysql.portal.PortalDeptMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;


/**
 * 门户网站用户部门 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PortalDeptServiceImpl  implements PortalDeptService {

    @Resource
    private PortalDeptMapper portalDeptMapper;

    @Override
    public String createDept(PortalDeptSaveReqVO createReqVO) {
        // 插入
        PortalDeptDO dept = BeanUtils.toBean(createReqVO, PortalDeptDO.class);
        portalDeptMapper.insert(dept);
        // 返回
        return dept.getOrgCode();
    }

    @Override
    public void updateDept(PortalDeptSaveReqVO updateReqVO) {
        // 更新
        PortalDeptDO updateObj = BeanUtils.toBean(updateReqVO, PortalDeptDO.class);
        portalDeptMapper.updateById(updateObj);
    }

    @Override
    public void deleteDept(String id) {
        // 删除
        portalDeptMapper.deleteById(id);
    }

    @Override
        public void deleteDeptListByIds(List<String> ids) {
        // 删除
        portalDeptMapper.deleteByIds(ids);
        }

    @Override
    public PortalDeptDO getDept(String id) {
        return portalDeptMapper.selectById(id);
    }

    @Override
    public PageResult<PortalDeptDO> getDeptPage(PortalDeptPageReqVO pageReqVO) {
        return portalDeptMapper.selectPage(pageReqVO);
    }

    @Override
    public void deleteAll() {
        QueryWrapper<PortalDeptDO> queryWrapper = new QueryWrapper<>();

        portalDeptMapper.delete(queryWrapper);
    }

    @Override
    public void batchCreateDept(List<PortalDeptSaveReqVO> orgList) {
        for (PortalDeptSaveReqVO portalDeptSaveReqVO : orgList){
            portalDeptMapper.insert(BeanUtils.toBean(portalDeptSaveReqVO, PortalDeptDO.class));
        }
    }

    @Override
    public List<PortalDeptRespVO> getDeptList() {
        return portalDeptMapper.getDeptList();
    }

}